// pages/person/person.js
const app = getApp()
import { HTTP } from '../../utils/https.js'
let http = new HTTP()
var util = require('../../utils/util.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    headurl: '../../image/noheader.png', //头像图片
    follow_me:'', //粉丝
    me_collect:'', //收藏
    me_follow:'',//关注的人
    is_authenticate:'', //是否认证
    name:'',//姓名
    region:'', //地点
    demand_number: '', //我的发布数量
    demand_apply_number: '',//我报名的数量
    weixin:'', //是否绑定微信
    phone:'',// 手机号码a
    is_contact:'',
    is_material:'',
    hasshowname:false, //是否显示登录注册
    rzfixbox:false,
    identity:'', //身份判断
    career:'',//职业
    identity_children:'', //招聘者身份类型
    company_name:'', //公司名称
    careerjpb:'',//工作
    checkrole:'',
    user_id:'' //用户自己的id
  },
  /**
    * 生命周期函数--监听页面加载
   */
  onShow: function (options) {
    if(wx.getStorageSync('checklogin') == 'checklogin'){
      this.infor();
    }

    this.setData({
      checkrole:wx.getStorageSync('checkrole'),
      user_id:wx.getStorageSync("user_id")
    })
  },
  onShareAppMessage: function () {
    return util.share()
  },
  //个人信息
    infor:function(){
      var that= this;
      http.request({
        url: 'mini/v1/personal/info',
        success: function (res) {
          wx.hideLoading();
          wx.setStorageSync('headimgurl', res.data.headimgurl);
          that.setData({
            headurl: res.data.headimgurl,
            follow_me: res.data.follow_me,
            me_collect: res.data.me_collect,
            me_follow: res.data.me_follow,
            is_authenticate: res.data.is_auth,
            name: res.data.name,
            region: res.data.region,
            demand_number: res.data.demand_number,
            demand_apply_number: res.data.demand_apply_number,
            weixin: res.data.is_weixin,
            phone: res.data.phone,
            is_material: res.data.is_material,
            is_contact: res.data.is_contact,
            hasshowname:true,
            identity:res.data.identity == 'boss' ? 2 : 1,
            career:res.data.career,
            identity_children:res.data.identity_children,
            company_name:res.data.company_name,
            careerjpb:res.data.identity == 'boss' ? res.data.career_company : res.data.career,
          })

          if(res.data.identity !== 'boss'){
            that.setData({
              identity_children:'personal'
            })
          }
        }
      })
    },
  //退出登录
  submit: function () {
    wx.redirectTo({
      url: '../../other/login/login'
    })
  },
  login:function(){
    if(wx.getStorageSync('checklogin') !== 'checklogin'){
      wx.redirectTo({
        url: '../../other/login/login'
      })
    }
  },
  //判断是否登录
  checklogins(){
    if(wx.getStorageSync('checklogin') !== 'checklogin'){
      wx.showModal({
        title: '提示',
        content: '登录后才可查看操作，是否进行登录?',
        confirmColor: '#f45859',
        confirmText: '去登录',
        success(res) {
          if (res.confirm) {
            wx.redirectTo({
              url: '../../other/login/login',
              success: res => { 
              }
            },
            );
          } else if (res.cancel) {
            wx.navigateBack({ changed: true });
          }
        }
      });
    }
  },
  hot:function(){
    wx.navigateTo({
      url: '../../hots/hot/hot',
    })
  },
  /***
   * 未认证点击
   * 
   */
    authenticate:function(){
      if(this.data.identity == 2){
         this.setData({
           rzfixbox:true
         })
         return false
      }
      
      wx.navigateTo({
        url: '../../other/certificates/certificates?type="parsonal"'
      })
    },
  /****隐藏认证弹窗
   * 
   */
    hiderzfixbox:function(){
      this.setData({
        rzfixbox:false
      })
    },
  /***认证类型点击进入认证页面 
   * 
  */
   certificates(e){
      const that = this 
      wx.navigateTo({
        url: '../../other/certificates/certificates?type='+e.currentTarget.dataset.type,
        success:function(){
          that.setData({
            rzfixbox:false
          })
        }
      })
   }
     
})